package com.gko100.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.struts2.ServletActionContext;

import com.gko100.action.base.AdminBaseAction;
import com.gko100.model.Article;
import com.gko100.model.Category;
import com.gko100.model.Disease;
import com.gko100.model.Image;
import com.gko100.model.Language;
import com.gko100.model.Navigation;
import com.gko100.util.DateTimeUtil;
import com.gko100.util.FileDel;
import com.gko100.vo.ImageVo;
import com.gko100.vo.NavArtiVo;
import com.gko100.vo.NewsArti;
import com.opensymphony.xwork2.ActionContext;

public class ArtiAction extends AdminBaseAction {
	
	private Article arti;
	private List<Article> artiList;
	
	public Article getArti() {
		return arti;
	}
	public void setArti(Article arti) {
		this.arti = arti;
	}
	public List<Article> getArtiList() {
		return artiList;
	}
	public void setArtiList(List<Article> artiList) {
		this.artiList = artiList;
	}
	
	private static int pageSize = 20;
	private long totalCount;
	private int pageNo;
	private int pageCount;

	
	public int getPageSize() {
		return pageSize;
	}
	
	public long getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	
	
	private Category cate;
	private List<Category> cateList;
	
	public Category getCate() {
		return cate;
	}
	public void setCate(Category cate) {
		this.cate = cate;
	}
	public List<Category> getCateList() {
		return cateList;
	}
	public void setCateList(List<Category> cateList) {
		this.cateList = cateList;
	}

	
	private Navigation nav;
	private List<Navigation> navList;
	private Map<Navigation, List<Navigation>> navMap; 

	public Navigation getNav() {
		return nav;
	}
	public void setNav(Navigation nav) {
		this.nav = nav;
	}
	public List<Navigation> getNavList() {
		return navList;
	}
	public void setNavList(List<Navigation> navList) {
		this.navList = navList;
	}
	public Map<Navigation, List<Navigation>> getNavMap() {
		return navMap;
	}
	public void setNavMap(Map<Navigation, List<Navigation>> navMap) {
		this.navMap = navMap;
	}

	private String[] navIdList;
	private String[] navIdList1;
	private String[] navIdList2;

	public String[] getNavIdList() {
		return navIdList;
	}
	public void setNavIdList(String[] navIdList) {
		this.navIdList = navIdList;
	}
	public String[] getNavIdList1() {
		return navIdList1;
	}
	public void setNavIdList1(String[] navIdList1) {
		this.navIdList1 = navIdList1;
	}
	public String[] getNavIdList2() {
		return navIdList2;
	}
	public void setNavIdList2(String[] navIdList2) {
		this.navIdList2 = navIdList2;
	}

	private Language lang;
	
	public Language getLang() {
		return lang;
	}
	public void setLang(Language lang) {
		this.lang = lang;
	}

	private String checkboxListDel;
	
	public String getCheckboxListDel() {
		return checkboxListDel;
	}
	public void setCheckboxListDel(String checkboxListDel) {
		this.checkboxListDel = checkboxListDel;
	}
	
	
	private int artiCount=0;
	
	public int getArtiCount() {
		return artiCount;
	}
	public void setArtiCount(int artiCount) {
		this.artiCount = artiCount;
	}
	
	private String param_cateId;

	public String getParam_cateId() {
		return param_cateId;
	}
	public void setParam_cateId(String paramCateId) {
		param_cateId = paramCateId;
	}

	private String[] diseListId1;
	private String[] diseListId2;
	private Disease disease;
	private List<Disease> diseaseList;
	private Map<Disease, List<Disease>> diseMap;
	public String[] getDiseListId1() {
		return diseListId1;
	}
	public void setDiseListId1(String[] diseListId1) {
		this.diseListId1 = diseListId1;
	}
	public String[] getDiseListId2() {
		return diseListId2;
	}
	public void setDiseListId2(String[] diseListId2) {
		this.diseListId2 = diseListId2;
	}
	public Disease getDisease() {
		return disease;
	}
	public void setDisease(Disease disease) {
		this.disease = disease;
	}
	public List<Disease> getDiseaseList() {
		return diseaseList;
	}
	public void setDiseaseList(List<Disease> diseaseList) {
		this.diseaseList = diseaseList;
	}
	
	public Map<Disease, List<Disease>> getDiseMap() {
		return diseMap;
	}
	public void setDiseMap(Map<Disease, List<Disease>> diseMap) {
		this.diseMap = diseMap;
	}
	
	//遍历疾病分类
	public List<Disease> cycDiseaseList(int disPid){
		
		List<Disease> diseList = new LinkedList<Disease>();
		List<Disease> dList = adminManager.findDisListByDisPid(disPid);
		if(dList!=null&&dList.size()>=1){
			
			for(int i=0;i<dList.size();i++){
				
				diseList.add(dList.get(i));
				List<Disease> dl = this.cycDiseaseList(dList.get(i).getDiseaseId());
				if(dl!=null&&dl.size()>=1){
					diseList.addAll(dl);
				}
			}
		}		
		return diseList;
	}
	
	////文章添加----------可以添加技术服务、技术应用、特色专科、合作加盟、关于我们、行业知识 
	private Integer[] diseaseIdList;
	
	public Integer[] getDiseaseIdList() {
		return diseaseIdList;
	}
	public void setDiseaseIdList(Integer[] diseaseIdList) {
		this.diseaseIdList = diseaseIdList;
	}
	public String insert_arti() throws Exception {
		
		if(this.getNavMap()!=null){
			this.setNavMap(null);
		}
		if(this.getNavList()!=null){
			this.setNavList(null);
		}
		if(this.getNavIdList()!=null){
			this.setNavIdList(null);
		}
		if(this.getNavIdList1()!=null){
			this.setNavIdList1(null);
		}
		if(this.getNavIdList2()!=null){
			this.setNavIdList2(null);
		}
		if(this.getDiseaseIdList()!=null){
			this.setDiseaseIdList(null);
		}
		ActionContext ctx = ActionContext.getContext();
		
		if(this.getCate().getCateId()!=null){
			
			
			Category cate = adminManager.findCateByCateId(this.getCate().getCateId());
			if(cate!=null){
				this.setCate(cate);
				ctx.getSession().put("cateId", this.getCate().getCateId());
				List<Category> cateList = adminManager.findCateListByCatePid(this.getCate().getCateId());
				if(cateList!=null&&cateList.size()>=1){
					this.setCateList(cateList);
				}
				Language lang = this.getCate().getLang();
				if(lang!=null){
					ctx.getSession().put("lang", lang);
				}
				
				
				Navigation nav = adminManager.findNavByCate(cate);
				if(nav!=null){
					this.setNav(nav);
					if(ctx.getSession().get(nav.getNavNote()+"List")!=null){
						ctx.getSession().remove(nav.getNavNote()+"List");
					}
					ctx.getSession().put("nav", this.getNav().getNavNote());
					
					List<Navigation> navList = adminManager.findNavListByNavPId(this.getNav().getNavId());
					if(navList!=null){
						this.setNavList(navList);
						Map<Navigation, List<Navigation>> nMap = new LinkedHashMap<Navigation, List<Navigation>>();
						for(int i=0;i<navList.size();i++){
							Navigation n = navList.get(i);
							
							List<Navigation> nl = adminManager.findNavListByNavPId(n.getNavId());
							
							if(nl!=null&&nl.size()>=1){
								nMap.put(n, nl);
							}else{
								nMap=null;
							}
							
						}
						this.setNavMap(nMap);
					}else{
						this.setNavList(null);
					}
					if(this.getNavMap()!=null){
						this.setNavList(null);
					}	
				}
				Map<Disease, List<Disease>> diseMap = new LinkedHashMap<Disease, List<Disease>>();
				List<Disease> diseList = adminManager.findDisListByDisPid(0);
				
				if(diseList!=null&&diseList.size()>=1){
					
					for(int i=0;i<diseList.size();i++){
						
						List<Disease> dList = adminManager.findDisListByDisPid(diseList.get(i).getDiseaseId());
						if(dList!=null&&dList.size()>=1){
							
							diseMap.put(diseList.get(i), dList);
						}else{
							diseMap.put(diseList.get(i), null);
						}
					}
					if(diseMap!=null&&diseMap.size()>=1){
						this.setDiseMap(diseMap);
					}
					
				}
				
			}

			List<Image> imageList=new ArrayList();
			ctx.getSession().put("imageList", imageList);
	
		}
		
		return "arti_insert_success";
	}

	public String add_arti() throws Exception{
		
		
		ActionContext ctx = ActionContext.getContext();
		int navId = -1;
		if(this.getNavIdList()!=null){
			navId = Integer.parseInt(this.getNavIdList()[0]);
			System.out.println("navId--------------"+navId);
			Navigation nav = adminManager.findNavByNavId(navId);
			if(nav!=null){
				this.getArti().setNav(nav);
				this.getArti().setArtiNote(nav.getNavNote());
				this.setNav(nav);
				
			}
		}else if(this.getNavIdList2()!=null){
			navId = Integer.parseInt(this.getNavIdList2()[0]);
			Navigation nav = adminManager.findNavByNavId(navId);
			if(nav!=null){
				this.getArti().setNav(nav);
				this.setNav(nav);
				this.getArti().setArtiNote(nav.getNavNote());
			}
			
		}else{
			if(this.getNav()!=null){
				this.getArti().setNav(this.getNav());
				this.getArti().setArtiNote(nav.getNavNote());
			}
			
		}
		this.getArti().setCheckup(false);
		this.getArti().setClickNums(0);
		this.getArti().setHeadLine(false);
		
		Language lang = (Language)ctx.getSession().get("lang");
		if(lang!=null){
			this.getArti().setLang(lang);
		}
		Category cate = adminManager.findCateByCateId(Integer.parseInt(ctx.getSession().get("cateId").toString()));
		if(cate!=null){
			this.setCate(cate);
		}
		this.getArti().setDeleteFlag(false);
		
		adminManager.add_arti(this.getArti());
		if(this.getDiseaseIdList()!=null){
			
			
			Set<Disease> diseSet = new LinkedHashSet<Disease>();
			for(int i=0;i<this.getDiseaseIdList().length;i++){
				Disease dis = adminManager.findDisByDisId(this.getDiseaseIdList()[i]);
				if(dis!=null){
					diseSet.add(dis);
				}	
			}
			this.getArti().setDiseSet(diseSet);
			adminManager.modify_arti(this.getArti());
		}	
		ImageVo imageVo = (ImageVo) ctx.getSession().get("imageVo");
		
		Image image = new Image();
		if(imageVo!=null){
			
			image.setImgSaveName(imageVo.getImageSaveName());
			image.setImgSrcName(imageVo.getImageSrcName());
			image.setImgUrl(imageVo.getImageUrl());
			
			image.setArti(this.getArti());
			image.setUploadTime(DateTimeUtil.getNowTime());
			image.setDeleteFlag(false);
			image.setMemo(null);

			adminManager.add_image(image);
			this.getArti().setVideoImageUrl(image.getImgSrcName()+image.getImgSaveName());
			adminManager.modify_arti(this.getArti());
			ctx.getSession().remove("imageVo");
			
		}
		List<Image> imageList=(List<Image>) ctx.getSession().get("imageList");
		if(imageList!=null&&imageList.size()>=1){
			for(int i=0;i<imageList.size();i++){
				Image img = imageList.get(i);
				img.setUploadTime(DateTimeUtil.getNowTime());
				img.setDeleteFlag(false);
				
				System.out.println(this.getArti().getArtiId());
				if(this.getArti()!=null){
					img.setArti(this.getArti());
				}
				
				if(this.getNav().getNavNote()!=null){
					img.setMemo(this.getNav().getNavNote());
				}

				adminManager.add_image(img);
				ctx.getSession().remove("imageList");
			}
		}
		
		if(this.getDiseaseIdList()!=null){
			this.setDiseaseIdList(null);
		}
		
		this.setNavIdList(null);
		this.setNavIdList1(null);
		this.setNavIdList2(null);
		this.setArti(null);
		
		
		
		return "arti_add_success";
	}
	
	public String del_arti() throws Exception{
		Article arti=adminManager.findArtiByArtiId(this.getArti().getArtiId());	
		List<Image> imageList = adminManager.findImageByArti(arti);
		if(imageList!=null&&imageList.size()>=1){
			for(int i=0;i<imageList.size();i++){
				adminManager.del_imageByImage(imageList.get(i));
			}
		}
		
		adminManager.del_arti(arti);
		return "arti_del_success";
	}
	public String cdel_arti() throws Exception {
		
		if(this.getArti()!=null&&this.getArti().getArtiId()!=null){
			
			Article arti = adminManager.findBackArtiByArtiId(this.getArti().getArtiId());
			if(arti!=null){
				List<Image> imageList = adminManager.findImageListDelByArti(arti);
				boolean flag =false;
				if(imageList!=null&&imageList.size()>=1){
					
					FileDel fileDel = new FileDel();
					for(int i=0;i<imageList.size();i++){
						Image image = imageList.get(i);
						String path = ServletActionContext.getServletContext().getRealPath(image.getImgSrcName()+image.getImgSaveName());
						flag = fileDel.del_file(path);
						if(flag){
							adminManager.cdel_imageByImage(image);
						}
					}
				}else{
					flag = true;
				}
				
				if(flag){
					adminManager.cdel_arti(arti);
				}
				
			}
		}
		return "arti_cdel_success";
	}
	
	public String del_artiList() throws Exception{
		
		String delId[] = this.getCheckboxListDel().split(", ");
		if(delId!=null&&delId.length>=1){
			for(int i=0;i<delId.length;i++){		
				Article arti=adminManager.findArtiByArtiId(Integer.parseInt(delId[i]));
				List<Image> imageList = adminManager.findImageByArti(arti);
				if(imageList!=null&&imageList.size()>=1){
					for(int j=0;j<imageList.size();j++){
						adminManager.del_imageByImage(imageList.get(j));
					}
				}
				
				adminManager.del_arti(arti);
			}
			return "artiList_del_success";
		}else{
			logger.debug(new Exception().getStackTrace()[0].getMethodName()+"------error");
			return "error";
		}
		
	}
	
	
	
	public List<Navigation> cycleNavList(Navigation nav){
		
		List<Navigation> navList = new LinkedList<Navigation>();
		
		if(nav!=null){
			
			List<Navigation> nList = adminManager.findNavListByNavPId(nav.getNavId());
			if(nList!=null&&nList.size()>=1){
				for(int i=0;i<nList.size();i++){
					navList.add(nList.get(i));
					List<Navigation> nl = this.cycleNavList(nList.get(i));
					if(nl!=null&&nl.size()>=1){
						navList.addAll(nl);
					}
				}
			}
		}
				
		return navList;
	}
	
	private List<NavArtiVo> navArtiVoList;
	
	public List<NavArtiVo> getNavArtiVoList() {
		return navArtiVoList;
	}
	public void setNavArtiVoList(List<NavArtiVo> navArtiVoList) {
		this.navArtiVoList = navArtiVoList;
	}
	public String find_artiList() throws Exception{
		
		if(this.getNav()!=null){
			this.setNav(null);
		}
		if(this.getArtiList()!=null){
			this.setArtiList(null);
		}
		if(this.getTotalCount()!=0){
			this.setTotalCount(0);
		}
		if(this.getNavArtiVoList()!=null){
			this.setNavArtiVoList(null);
		}
		ActionContext ctx = ActionContext.getContext();

		Category cate = null;
		if(this.getCate().getCateId()!=null){
			cate = adminManager.findCateByCateId(this.getCate().getCateId());
			ctx.getSession().put("cateId", cate.getCateId());
		}else if(this.getParam_cateId()!=null){
			cate = adminManager.findCateByCateId(Integer.parseInt(this.getParam_cateId()));
			ctx.getSession().put("cateId", cate.getCateId());
		}
		
		if(cate!=null){
			this.setCate(cate);
			List<Category> cateList = adminManager.findCateListByCatePid(this.getCate().getCateId());
			if(cateList!=null){
				this.setCateList(cateList);
			}
			Navigation nav = adminManager.findNavByCate(cate);
			
			if(nav!=null){
				
				this.setNav(nav);
				List<Navigation> navList = this.cycleNavList(nav);
				if(navList!=null&&navList.size()>=1){
					long totalCount = adminManager.find_backArtiTotalCountByNav(navList);
					this.setTotalCount(totalCount);
					int pageCount = (int) (this.getTotalCount()/this.getPageSize()+1);
					
					this.setPageCount(pageCount);
					if(this.getTotalCount()==0){
						this.setPageCount(0);
					}
					if(this.getPageNo()==0){
						this.setPageNo(1);
					}
					if(this.getTotalCount()==0){
						this.setPageNo(0);
					}
					
					if(this.getPageNo()==1){
						
						int offset =0;
						List<NavArtiVo> nal = new LinkedList<NavArtiVo>();

						List<Article> artiList = adminManager.findBackArtiListByNavAndPage(navList, offset, this.getPageSize());
						if(artiList!=null&&artiList.size()>=1){
							
							for(int i=0;i<artiList.size();i++){
								Article arti = artiList.get(i);
								NavArtiVo na = new NavArtiVo();
								na.setArtiId(arti.getArtiId());
								na.setArtiPrio(arti.getArtiPrio());
								na.setArtiTitle(arti.getArtiTitle());
								na.setAuthor(arti.getArtiAuthor());
								na.setCheckup(arti.getCheckup());
								na.setClickNums(arti.getClickNums());
								na.setDeleteFlag(arti.getDeleteFlag());
								na.setHeadLine(arti.getHeadLine());
								na.setAddDate(arti.getAddDate());
								Navigation n = arti.getNav();
								if(n!=null){
									na.setNavId(n.getNavId());
									na.setNavTitle(n.getNavName());
								}
								nal.add(na);
							}
							
						}
						if(nal!=null&&nal.size()>=1){	
							this.setNavArtiVoList(nal);
						}			
					
					}
					
					if(this.getPageNo()>1&&this.getPageNo()<=this.getPageCount()){
						
						
						int offset = (this.getPageNo()-1)*this.getPageSize();
						List<NavArtiVo> nal = new LinkedList<NavArtiVo>();	
						List<Article> artiList = adminManager.findBackArtiListByNavAndPage(navList, offset, this.getPageSize());
						
						if(artiList!=null&&artiList.size()>=1){
							
							for(int i=0;i<artiList.size();i++){
								Article arti = artiList.get(i);
								NavArtiVo na = new NavArtiVo();
								na.setArtiId(arti.getArtiId());
								na.setArtiPrio(arti.getArtiPrio());
								na.setArtiTitle(arti.getArtiTitle());
								na.setAuthor(arti.getArtiAuthor());
								na.setCheckup(arti.getCheckup());
								na.setClickNums(arti.getClickNums());
								na.setDeleteFlag(arti.getDeleteFlag());
								na.setHeadLine(arti.getHeadLine());
								na.setAddDate(arti.getAddDate());
								Navigation n = arti.getNav();
								if(n!=null){
									na.setNavId(n.getNavId());
									na.setNavTitle(n.getNavName());
								}
								nal.add(na);
							}
							
						}
						if(nal!=null&&nal.size()>=1){	
							this.setNavArtiVoList(nal);
						}			

						
						
					}
				}else{
					List<Navigation> nList = new LinkedList<Navigation>();
					nList.add(nav);
					long totalCount = adminManager.find_backArtiTotalCountByNav(nList);
					this.setTotalCount(totalCount);
					int pageCount = (int) (this.getTotalCount()/this.getPageSize()+1);
					this.setPageCount(pageCount);
					
					if(this.getPageNo()==0){
						this.setPageNo(1);
					}
					if(this.getTotalCount()==0){
						this.setPageNo(0);
					}
					
					if(this.getPageNo()==1){
						
						int offset =0;
						List<Article> artiList = adminManager.findBackArtiListByNavAndPage(nList, offset, this.getPageSize());
						List<NavArtiVo> nal = new LinkedList<NavArtiVo>();
						if(artiList!=null&&artiList.size()>=1){
							
							for(int i=0;i<artiList.size();i++){
								Article arti = artiList.get(i);
								NavArtiVo na = new NavArtiVo();
								na.setArtiId(arti.getArtiId());
								na.setArtiPrio(arti.getArtiPrio());
								na.setArtiTitle(arti.getArtiTitle());
								na.setAuthor(arti.getArtiAuthor());
								na.setCheckup(arti.getCheckup());
								na.setClickNums(arti.getClickNums());
								na.setDeleteFlag(arti.getDeleteFlag());
								na.setHeadLine(arti.getHeadLine());
								na.setAddDate(arti.getAddDate());
								Navigation n = arti.getNav();
								if(n!=null){
									na.setNavId(n.getNavId());
									na.setNavTitle(n.getNavName());
								}
								nal.add(na);
							}
							
						}
						if(nal!=null&&nal.size()>=1){
							
							this.setNavArtiVoList(nal);
						}						
					}
					
					if(this.getPageNo()>1&&this.getPageNo()<=this.getPageCount()){
						
						List<NavArtiVo> nal = new LinkedList<NavArtiVo>();
						int offset = (this.getPageNo()-1)*this.getPageSize();
						List<Article> artiList = adminManager.findBackArtiListByNavAndPage(nList, offset, this.getPageSize());
							
						if(artiList!=null&&artiList.size()>=1){
							
							for(int i=0;i<artiList.size();i++){
								Article arti = artiList.get(i);
								NavArtiVo na = new NavArtiVo();
								na.setArtiId(arti.getArtiId());
								na.setArtiPrio(arti.getArtiPrio());
								na.setArtiTitle(arti.getArtiTitle());
								na.setAuthor(arti.getArtiAuthor());
								na.setCheckup(arti.getCheckup());
								na.setClickNums(arti.getClickNums());
								na.setDeleteFlag(arti.getDeleteFlag());
								na.setHeadLine(arti.getHeadLine());
								na.setAddDate(arti.getAddDate());
								Navigation n = arti.getNav();
								if(n!=null){
									na.setNavId(n.getNavId());
									na.setNavTitle(n.getNavName());
								}
								nal.add(na);
							}
							
						}
						if(nal!=null&&nal.size()>=1){
							
							this.setNavArtiVoList(nal);
						}		

					}
				}
			}
		}
		
		return "artiList_find_success";
	
	}
	
	public String upload_arti() throws Exception {
		
		if(this.getNavList()!=null){
			this.setNavList(null);
		}
		if(this.getDiseaseIdList()!=null){
			this.setDiseaseIdList(null);
		}
		if(this.getDiseMap()!=null){
			this.setDiseMap(null);
		}
		ActionContext ctx = ActionContext.getContext();
		if(ctx.getSession().get("cateId")!=null){
			Category cate = adminManager.findCateByCateId(Integer.parseInt(ctx.getSession().get("cateId").toString()));
			this.setCate(cate);
			ctx.getSession().put("nav", cate.getCateNote());
			Navigation nav = adminManager.findNavByCate(this.getCate());
			if(nav!=null){
				
				List<Navigation> navList = adminManager.findNavListByNavPId(nav.getNavId());
				if(navList!=null){
					this.setNavList(navList);
				}
			}
		}

		Article arti = adminManager.findArtiByArtiId(this.getArti().getArtiId());
		this.setArti(arti);

		Map<Disease, List<Disease>> diseMap = new LinkedHashMap<Disease, List<Disease>>();
		List<Disease> diseList = adminManager.findDisListByDisPid(0);
		
		if(diseList!=null&&diseList.size()>=1){
			
			for(int i=0;i<diseList.size();i++){
				
				List<Disease> dList = adminManager.findDisListByDisPid(diseList.get(i).getDiseaseId());
				if(dList!=null&&dList.size()>=1){
					
					diseMap.put(diseList.get(i), dList);
				}else{
					diseMap.put(diseList.get(i), null);
				}
			}
			if(diseMap!=null&&diseMap.size()>=1){
				this.setDiseMap(diseMap);
			}
			
		}
		List<Disease> dList = adminManager.findDiseListByArticle(arti);
		if(dList!=null&&dList.size()>=1){
			Integer[] diseIdList = new Integer[dList.size()];
			for(int i=0;i<dList.size();i++){
				diseIdList[i] = dList.get(i).getDiseaseId();
			}
			if(diseIdList!=null&&diseIdList.length>=1){
				this.setDiseaseIdList(diseIdList);
			}
		}
		
		return "arti_upload_success";
	}
	
	public String modify_arti() throws Exception{
		
		ActionContext ctx = ActionContext.getContext();
		if(ctx.getSession().get("cateId")!=null){
			Category cate = adminManager.findCateByCateId(Integer.parseInt(ctx.getSession().get("cateId").toString()));
			this.setCate(cate);
			
		}
		Navigation nav = null;
		if(navIdList2!=null){
			nav = adminManager.findNavByNavId(Integer.parseInt(this.getNavIdList2()[0]));
			if(nav!=null){
				this.getArti().setNav(nav);
			}
			
		}else if(navIdList!=null){
			nav = adminManager.findNavByNavId(Integer.parseInt(this.getNavIdList()[0]));
			if(nav!=null){
				this.getArti().setNav(nav);
			}
		}
		
		this.getArti().setCheckup(false);
		adminManager.modify_arti(this.getArti());
		if(this.getDiseaseIdList()!=null){
			
			
			Set<Disease> diseSet = new LinkedHashSet<Disease>();
			for(int i=0;i<this.getDiseaseIdList().length;i++){
				Disease dis = adminManager.findDisByDisId(this.getDiseaseIdList()[i]);
				if(dis!=null){
					diseSet.add(dis);
				}	
			}
			this.getArti().setDiseSet(diseSet);
			adminManager.modify_arti(this.getArti());
		}	
		ImageVo imageVo = (ImageVo) ctx.getSession().get("imageVo");
		
		Image image = new Image();
		if(imageVo!=null){
			List<Image> iList = adminManager.findImageByArti(this.getArti());
			if(iList!=null&&iList.size()>=1){
				for(int i=0;i<iList.size();i++){
					Image img = iList.get(i);
					if(img!=null){
						adminManager.del_imageByImage(img);
					}
				}
			}
			image.setImgSaveName(imageVo.getImageSaveName());
			image.setImgSrcName(imageVo.getImageSrcName());
			image.setImgUrl(imageVo.getImageUrl());
			
			image.setArti(this.getArti());
			image.setUploadTime(DateTimeUtil.getNowTime());
			image.setDeleteFlag(false);
			image.setMemo(null);

			adminManager.add_image(image);
			this.getArti().setVideoImageUrl(image.getImgSrcName()+image.getImgSaveName());
			ctx.getSession().remove("imageVo");
			
		}
		
		List<Image> imageList=(List<Image>) ctx.getSession().get("imageList");
		if(imageList!=null&&imageList.size()>=1){
			
			//删除原有图片
			List<Image> iList = adminManager.findImageByArti(this.getArti());
			if(iList!=null&&iList.size()>=1){
				for(int i=0;i<iList.size();i++){
					Image img = iList.get(i);
					if(img!=null){
						adminManager.del_imageByImage(img);
					}
				}
			}
			//添加新的图片
			for(int i=0;i<imageList.size();i++){
				Image img = imageList.get(i);
				img.setDeleteFlag(false);
				img.setMemo("siteInfo");
				Timestamp uploadTime = DateTimeUtil.getNowTime();
				img.setUploadTime(uploadTime);
				img.setArti(this.getArti());
				
				adminManager.add_image(img);

				ctx.getSession().remove("imageList");
			}
		}
		
		return "arti_modify_success";
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
